define(function () {

    var self,
        gwat310_02_page,
        good,
        refreshData = {
            key: 0, //评价key
            status: 0,
            count: 0,
            count1: 0,
            count2: 0,
            count3: 0,
            pv: 0
        },
        updateData = {
            GWCS050: '',//备注
            GWCS019: '',//序列号
            GWCS016: '',//投入使用日期
            GWCS104: '',//合同编号
        }
    ;
    var scroll1;

    var gwat310_02 = app.Module.extend({

        init: function () {
            self = this;
            self.GWCS017S = [];

            gwat310_02_page = app.pageParameters['gwat310_02_page'];
            good = gwat310_02_page.good;
            app.extend(updateData, good);
            if (good.GWCS017 != null) {
                self.GWCS017S = good.GWCS017.split(',');
            }

            if(!good.imgs){
                good.imgs = [];
            }

            self._super({}, win);
        },
        getGwcwCount: function () {
            app.ajax({
                xurl: "api/wx/gwat100/getGwcwCount",
                // xtime: '1d',
                xdata: {
                    GWCW020: good.GWAM001,
                    GWAM005: 1, //子料号类型
                    status: refreshData.status // 0全部 1当前商品评论用于子料号
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data.data.count;
                        app.extend(refreshData, data);
                        if (data.count > 0) {
                            refreshData.pv = (refreshData.count1 / refreshData.count * 100).toFixed(2);
                        } else {
                            refreshData.pv = 0;
                        }
                    }
                }
            });
        },
        _ready: function () {

            new Vue({
                el: doc.getElementById('footDiv'),
                methods: {
                    reback: function () {
                        delete good.imgs;
                        app.back(1);
                    },
                    save: function () {
                        app.extend(good, updateData);
                        app.back(1);
                    }
                }
            });

            scroll1 = new Vue({
                el: doc.getElementById('scroll1'),
                data: function () {
                    return {
                        good: good,
                        ud: updateData,
                        imgs: good.imgs,
                        GWCS017S: self.GWCS017S
                    }
                },
                methods: {
                    btn_gwcs019: function () {
                        app.scanQRCode(function (result) {
                            updateData.GWCS019 = result;
                        });
                    },
                    btn_gwcs104: function () {
                        app.scanQRCode(function (result) {
                            updateData.GWCS104 = result;
                        });
                    },
                    delimgGwcs017: function (i) {
                        self.GWCS017S.removei(i);
                    },
                    delimg: function (i) {
                        good.imgs.removei(i);
                    },
                    addImgs: function () {
                        app.chooseImageNew(function (imgs) {
                            //good.imgs.pushArray(imgs);
                            for (var i = 0; i < imgs.length; i++) {
                                good.imgs.push({
                                    img: imgs[i].img,
                                    id: imgs[i].localId
                                })
                            }
                        });
                    }
                }
            });

            new Vue({
                el: doc.getElementById('scroll2'),
                data: function () {
                    return {
                        good: good
                    }
                }
            });

            Vue.component('commentsitem', {
                template: app.getByid(doc, 'comments-template'),
                props: {
                    model: Array
                }
            });

            $('.wf-infoTab ul li').on('tap', function () {
                $(this).addClass('active').siblings('li').removeClass('active');
                $(this).parents('.wf-infoTab').find('.tabCont .group').eq($(this).index()).show().siblings('.group').hide();
            });

            doc.getElementById('slider').addEventListener('slide', function (e) {
                if (e.detail.slideNumber == 2) {
                    self._initRefresh(win);
                }
            });
        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['scroll3'];
                self._refreshVueData = refreshData;
                self._refreshVueMethods = {
                    statusChange: function () {
                        self._refresh();
                        self.getGwcwCount();
                    },
                    getpj: function (val) {
                        refreshData.key = val;
                        self._refresh();
                    }
                };
                this._super(win);
            }else{
                self._refresh();
            }

            self.getGwcwCount();
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/gwat100/getGwcw",
                xdata: {
                    page:goods.page+1,
                    limit: goods.limit,
                    GWCW020: good.GWCS001,
                    key: refreshData.key,//评论级别
                    GWAM005: 1, //子料号类型
                    status: refreshData.status // 0全部 1当前商品评论用于子料号
                },
                cb: function (result) {
                    if (result.ok) {
                        var datas = result.data.data;

                        _super({
                            obj: goods,
                            data: datas,
                            nodata: '暂无评论信息...',
                            nodata_img: 'noneComment.png'
                        });
                    }
                }
            });
        }
    });

    return new gwat310_02();

});